<?php
/**
 * Created by PhpStorm.
 * User: 勇林
 * Date: 2015/12/11
 * Time: 15:48
 */

namespace app\api\controllers;


use app\api\Response;
use app\models\Project;
use yii\helpers\ArrayHelper;
use yii\web\Controller;

class ProjectController extends Controller
{
    public function actionList($pageNow, $pageSize){

        $list = Project::getList($pageNow, $pageSize);
        Response::setHeader();
        echo json_encode(ArrayHelper::toArray($list));
    }

    /**
     * 获取当前用户的所有项目
     *
     * @param $userid
     * @param $pageNow
     * @param $pageSize
     */
    public function actionProjects($userid,$pageNow, $pageSize){

        $list = Project::getList($pageNow, $pageSize);
        Response::setHeader();
        echo json_encode(ArrayHelper::toArray($list));
    }

       public function actionPersonprojects($username,$pageNow, $pageSize){

        $list = Project::findPersonProjects($username,$pageNow, $pageSize);
        Response::setHeader();
        echo json_encode(ArrayHelper::toArray($list));
    }
    public function actionDetail($id){

        $detail = Project::findOne(['id'=>$id]);
        Response::setHeader();
        echo json_encode(ArrayHelper::toArray($detail));
    }
    public function actionSearch($projectname){
         $projects= Project::find()
              ->where(['or',['like','chargeman',$projectname],['like','projectname',$projectname]])
              ->limit(5)
              ->all();
          Response::setHeader();
        echo json_encode(ArrayHelper::toArray($projects));
    }

}
